home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
001
/
pibt40s2.arc
/
MYLOADO.MOD
< prev
next >
Wrap
Text File
|
1987-04-23
|
10KB
|
228 lines
(*----------------------------------------------------------------------*)
(* MyLoadOverlay --- Load Turbo Extender overlay without abort *)
(*----------------------------------------------------------------------*)
FUNCTION MyLoadOverlay( OverlaySection: INTEGER;
ModuleNumber : INTEGER;
FileName : AnyStr ) : BOOLEAN;
(*----------------------------------------------------------------------*)
(* *)
(* Function: MyLoadOverlay *)
(* *)
(* Purpose: Loads Turbo Extender overlay if found *)
(* *)
(* Calling Sequence: *)
(* *)
(* Found := MyLoadOverlay( OverlaySection: INTEGER; *)
(* ModuleNumber : INTEGER; *)
(* FileName : AnyStr ) : BOOLEAN; *)
(* *)
(* OverlaySection --- Overlay section to load module into *)
(* ModuleNumber --- Module number to be loaded *)
(* FileName --- Chain file name containing module code *)
(* *)
(* Found --- TRUE if module found *)
(* *)
(* Remarks: *)
(* *)
(* This routine tries to load an overlay file. If it exists, *)
(* MyLoadOverlay is returned TRUE. If it is not found, a brief *)
(* message is printed, and MyLoadOverlay is returned FALSE. *)
(* *)
(* Note: Overlay sections 0 and 1 are real overlay sections. *)
(* *)
(*----------------------------------------------------------------------*)
VAR
Ch : CHAR;
I : INTEGER;
ModNo : INTEGER;
S : AnyStr;
BEGIN (* MyLoadOverlay *)
(* If this module is already loaded, *)
(* we don't need to reload it. *)
LoadingOverlay := FALSE;
IF ( ABS( ModuleLoaded[ModuleNumber] ) = OverlaySection ) THEN
BEGIN
MyLoadOverlay := TRUE;
END
ELSE
BEGIN
(* See if overlay file exists *)
IF ( NOT ExistFile( FileName , S ) ) THEN
BEGIN
(* If not, display message and return *)
MyLoadOverlay := FALSE;
IF Attended_Mode THEN
BEGIN
WRITELN;
WRITELN('Cannot load ',FileName,'.');
Press_Any;
WRITELN;
END;
END
ELSE
BEGIN
(* Otherwise, load it. *)
ModNo := -1;
FOR I := 1 TO MaxNumModules DO
IF ( ModuleLoaded[I] = OverlaySection ) THEN
ModNo := I;
(* Unload modules from heap, but *)
(* leave modules loaded in EMM *)
IF ( ModNo > 0 ) THEN
WITH BigModules[ModNo] DO
IF ( Handle = NOTInEMS ) THEN
BEGIN
UnLoadModule( ModNo );
ModuleLoaded[ModNo] := -99;
END
ELSE
ModuleLoaded[ModNo] := ( -OverlaySection );
(* Set up overlay load if needed *)
IF ( NOT Use_EMM_For_Overlays ) THEN
IF ( OverlaySection < 2 ) THEN
BEGIN (* Set up overlay load to RAM *)
LoadingOverlay := TRUE;
GlobalOverlayNum := OverlaySection;
END;
(* Load the module! *)
LoadModule( ModuleNumber , FileName , Use_EMM_For_Overlays );
LoadingOverlay := FALSE;
MyLoadOverlay := TRUE;
(* Mark this module as loaded *)
ModuleLoaded[ModuleNumber] := OverlaySection;
END;
END;
(* Make sure all resident code updated *)
CloneCodeSegment( TurboRunDataStart , TurboRunDataLength );
END (* MyLoadOverlay *);
(*----------------------------------------------------------------------*)
(* UnloadEmulator --- Unload terminal emulation module *)
(*----------------------------------------------------------------------*)
PROCEDURE UnloadEmulator;
(*----------------------------------------------------------------------*)
(* *)
(* Function: UnloadEmulator *)
(* *)
(* Purpose: Unloads terminal emulation module if loaded *)
(* *)
(* Calling Sequence: *)
(* *)
(* UnloadEmulator; *)
(* *)
(*----------------------------------------------------------------------*)
VAR
ModNo: INTEGER;
BEGIN (* UnloadEmulator *)
FOR Modno := 1 TO MaxNumModules DO
IF ( ModuleLoaded[ModNo] = 2 ) THEN
WITH BigModules[ModNo] DO
IF ( Handle = NOTInEMS ) THEN
BEGIN
UnLoadModule( ModNo );
ModuleLoaded[ModNo] := -99;
END
ELSE
ModuleLoaded[ModNo] := ( -2 );
END (* UnloadEmulator *);
(*----------------------------------------------------------------------*)
(* MyGetOverlayArea --- Set up overlay area (not standard Extender) *)
(*----------------------------------------------------------------------*)
PROCEDURE MyGetOverlayArea( OverlaySection: INTEGER;
FileName : AnyStr;
OSize : INTEGER );
(*----------------------------------------------------------------------*)
(* *)
(* Procedure: MyGetOverlayArea *)
(* *)
(* Purpose: Set up non-standard overlay area *)
(* *)
(* Calling Sequence: *)
(* *)
(* MyGetOverlayArea( OverlaySection: INTEGER; *)
(* FileName : AnyStr; *)
(* OSize : INTEGER ); *)
(* *)
(* OverlaySection --- Overlay section to initialize *)
(* FileName --- Chain file name containing module code *)
(* OSize --- Size of area to allocate if 'FileName' *)
(* is null. *)
(* *)
(* Remarks: *)
(* *)
(* This routine adds simple overlay stuff to the EMS version *)
(* of Turbo Extender, which doesn't have overlays. This is not *)
(* a very general implementation. *)
(* *)
(* Note: Overlay sections 0 and 1 are real overlay sections. *)
(* *)
(*----------------------------------------------------------------------*)
VAR
F : FILE;
FirstRunJump : INTEGER ABSOLUTE CSeg : $101;
FileSize : INTEGER;
RuntimeSize : INTEGER;
BEGIN (* MyGetOverlayArea *)
(* Get size of runtime library in bytes, *)
(* including PSP *)
RuntimeSize := FirstRunJump + $103;
(* Find file and get the file size *)
IF( LENGTH( FileName ) > 0 ) THEN
BEGIN
FileSize := ReturnFileInfo( FileName , F );
CLOSE( F );
END
ELSE
FileSize := OSize;
(* Check if new size same as old. If so *)
(* no need to reallocate memory. *)
WITH OverlayArea[OverlaySection] DO
BEGIN
Size := FileSize + RuntimeSize + $20;
GETMEM( Pointer , Size );
OverlaySeg := SUCC( Seg( Pointer^ ) );
CurrentModule := -1;
END;
END (* MyGetOverlayArea *);